package cn.su.utils;

import com.alibaba.druid.pool.DruidDataSourceFactory;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import javax.sql.DataSource;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

public class BaseDao {
   private static DataSource dataSource=null;
   static {
       try {
           Properties properties = new Properties();
           InputStream resourceAsStream = BaseDao.class.getClassLoader().getResourceAsStream("druid.properties");
           properties.load(resourceAsStream);
           dataSource=DruidDataSourceFactory.createDataSource(properties);
       } catch (Exception e) {
           e.printStackTrace();
       }
   }



//创建DButils工具类对象
public static QueryRunner getQueryRunner(){
       return new QueryRunner(dataSource);
    }



    //测试数据库连接
    public static void main(String[] args) throws SQLException {
        System.out.println(dataSource);
        Connection conn=dataSource.getConnection();
        System.out.println(conn);

    }

}
